<template>
  <div class="manage-wrapper">
    <c-title :hide="false" :text="'合伙人'"></c-title>
    <div class="background-box">
      <div class="user-info">
        <img class="user-avatar" :src="userInfo.avatar" alt="" />
        <div class="info-box">
          <div class="info">
            <span class="nickname">{{ userInfo.nickname }}</span>
            <span v-for="(item, index) in identity" :key="index" class="identity">{{ item }}</span>
          </div>
          <p>ID：{{ userInfo.id }}</p>
        </div>
        <div class="qrcode">
          <van-icon @click="getPoster" name="qr" size="40" />
        </div>
      </div>
      <div class="block">
        <div class="block-head">
          <van-cell
            :title="startStr + ' - ' + endStr"
            is-link
            @click="calendarVisible = true"
          />
          <van-calendar
            v-model="calendarVisible"
            type="range"
            title="请选择查询范围"
            :min-date="minDate"
            :max-date="maxDate"
            :default-date="defaultDate"
            @confirm="calendarConfirm"
          />
        </div>
        <div class="block-body">
          <div class="datas">
            <div class="data-item">
              <span class="data van-ellipsis">{{ partner.totality }}</span>
              <span>总次数</span>
            </div>
            <div class="data-item">
              <span class="data van-ellipsis">{{ partner.push_num }}</span>
              <span>剩余次数</span>
            </div>
            <div class="data-item">
              <span class="data van-ellipsis">{{ partner.merchantCount }}</span>
              <span>已推荐商家</span>
            </div>
            <div class="data-item">
              <span class="data van-ellipsis">{{ partner.dividend_amount }}</span>
              <span>提成总金额</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="block">
      <div class="block-body">
        <div class="tabs">
          <div :class="['tab-item', tabType == 1 ? 'active' : '']" @click="tabChange(1)">推广商家</div>
          <div :class="['tab-item', tabType == 2 ? 'active' : '']" @click="tabChange(2)">提成</div>
        </div>
        <van-pull-refresh v-model="refreshing" @refresh="refreshData">
          <van-list
            v-model="loading"
            :finished="finished"
            :finished-text="list.length ? '没有更多了' : ''"
            @load="getData"
          >
            <!-- <van-cell v-for="item in list" :key="item" :title="item" /> -->
            <van-skeleton title :row="2" :loading="isSkeleton">
              <template v-if="list.length">
                <div class="list" v-for="item in list" :key="item.id">
                  <!-- 推广商家 -->
                  <template v-if="tabType == 1">
                    <div class="list-merchant">
                      <img :src="item.thumb" class="thumb" />
                      <div class="merchant">
                        <p class="name">{{ item.store_name }}</p>
                        <p class="time">时间：{{ item.created_at }}</p>
                      </div>
                    </div>
                  </template>
                  <!-- 提成 -->
                  <template v-if="tabType == 2">
                    <div class="list-commission">
                      <div class="commission">
                        <p class="name">订单号：{{ item.order_sn }}</p>
                        <p class="dividend">{{ item.dividend_amount }}</p>
                      </div>
                      <div class="commission">
                        <p class="time">时间：{{ item.created_at }}</p>
                        <p :class="'status' + item.status">{{ item.status_name }}</p>
                      </div>
                    </div>
                  </template>
                </div>
              </template>
              <van-empty v-else description="暂无数据" />
            </van-skeleton>
          </van-list>
        </van-pull-refresh>
      </div>
    </div>
    <van-popup closeable round close-on-popstate v-model="qrShow">
      <div class="qr-box">
        <img class="qr-code" :src="imageUrl" />
      </div>
    </van-popup>
  </div>
</template>

<script>
import partnership_manage_controller from './partnership_manage_controller';

export default partnership_manage_controller;
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
.manage-wrapper {
  text-align: left;

  ::v-deep.van-nav-bar {
    background-color: #EB2818;

    .van-nav-bar__content {
      background: #EB2818;

      .van-nav-bar__title {
        color: #fff;
      }

      .van-button--default {
        background-color: #EB2818;
        
        .van-icon {
          color: #fff;
        }
      }
    }
  }

  .background-box {
    background-image: linear-gradient(to bottom, #EB2818, #f5f5f5);

    .user-info {
      color: #fff;
      display: flex;
      padding: 20px 20px 0 20px;

      .user-avatar {
        flex: 0 0 50px;
        width: 50px;
        height: 50px;
        border-radius: 50%;
      }
    }

    .info-box {
      flex: 1;
      margin-left: 8px;

      .info {
        display: flex;
        align-items: center;

        .nickname {
          font-size: 16px;
        }

        .identity {
          border-radius: 4px;
          color: #CE5E0E;
          font-size: 12px;
          padding: 4px;
          margin: 0 0 3px 5px;
          background-color: rgba(255, 255, 255, 0.8);
          font-weight: bold;
        }
      }
    }

    .qrcode {
      margin-left: 10px;
    }
  }

  .block {
    background-color: #fff;
    border-radius: 10px;
    margin: 10px;
    padding: 10px;

    .block-head {
      padding-bottom: 5px;
      border-bottom: 1px solid #eee;
      
      .van-cell::after {
        border: 0;
      }
    }

    .block-body {

      .datas {
        background-color: rgba(255, 193, 30, 0.1);
        border-radius: 5px;
        display: flex;
        flex-wrap: wrap;
        padding: 10px;
        margin-top: 10px;
        text-align: center;

        .data-item {
          display: flex;
          flex-direction: column;
          font-size: 12px;
          width: 25%;
          padding: 4px;

          .data {
            font-weight: bold;
            font-size: 15px;
            margin-bottom: 5px;
          }
        }
      }
    }
  }
  
  .tabs {
    display: flex;
    width: 20rem;
    margin: 0 auto;
    margin-bottom: 20px;
    border-radius: 8px;
    background-color: #e9e9e9;
    text-align: center;

    .tab-item {
      flex: 1;
      padding: 10px;
      color: #707070;

      &.active {
        background-color: var(--themeBaseColor);
        border-radius: 8px;
        color: #fff;
      }
    }
  }

  .list {
    padding: 10px;
    border-bottom: 1px solid #eee;

    .list-merchant {
      display: flex;
      align-items: center;

      .thumb {
        flex: 0 0 50px;
        width: 50px;
        height: 50px;
        border-radius: 50%;
      }

      .merchant {
        flex: 1;
        margin-left: 8px;
      }
    }

    .list-commission {

      .commission {
        display: flex;
        justify-content: space-between;
        margin: 4px 0;

        .dividend {
          color: #FB0606;
        }

        .status0 {
          color: #6b6b6b;
        }
        .status1 {
          color: #38E70E;
        }
      }
    }

    .name {
      font-size: 14px;
      font-weight: bold;
    }

    .time {
      color: #6b6b6b;
    }
  }

  .qr-box {
    padding: 20px;

    .qr-code {
      max-width: 100%;
      margin-top: 20px;
    }

    .qr-button {
      padding: 5px 0;
    }
  }
}
</style>
